package org.example.medical.service.impl;

import org.apache.ibatis.annotations.Mapper;
import org.example.medical.Mapper.SurgeryRecordMapper;
import org.example.medical.entity.SurgeryRecord;
import org.example.medical.service.SurgeryRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class SurgeryRecordServiceImpl implements SurgeryRecordService {
    @Autowired
    private SurgeryRecordMapper surgeryRecordMapper;
    @Override
    public List<SurgeryRecord> getSurgeryRecords(String patientName, String doctorName, String status, LocalDate scheduledDate, int page, int size) {
        int offset = (page - 1) * size;
        return surgeryRecordMapper.selectByPageAndFilters(
                patientName,
                doctorName,
                status,
                scheduledDate != null ? scheduledDate.toString() : null,
                offset,
                size
        );
    }

    @Override
    public void addSurgeryRecord(SurgeryRecord surgeryRecord) {
        surgeryRecordMapper.insertSurgeryRecord(surgeryRecord);
    }

    @Override
    public void updateSurgeryRecord(SurgeryRecord surgeryRecord) {
        surgeryRecordMapper.updateSurgeryRecord(surgeryRecord);

    }

    @Override
    public void softDeleteSurgeryRecord(Long surgeryId) {
        surgeryRecordMapper.softDeleteSurgeryRecord(surgeryId);

    }

    @Override
    public void batchSoftDeleteSurgeryRecords(List<Long> surgeryIds) {
        surgeryRecordMapper.batchSoftDeleteSurgeryRecords(surgeryIds);

    }
}
